package com.big.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.big.app.dao.ZancangDao;
import com.big.app.entity.Zancang;
import com.big.app.service.intf.ZancangService;
import com.big.app.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author: zjl
 * @description 将点赞收藏数量分为一张表,记录点赞收藏数量,独立存取,各司其职,另一张表记录用户点赞收藏状态。
 * @date: 2022/4/20 22:51
 */
@Service
public class ZancangServiceImpl implements ZancangService {
    @Resource
    private ZancangDao zancangDao;

    @Override
    public R selectDetail(Integer id) {
        if (zancangDao.selectDetail(id)!=null){
            return new R(200,"ok",zancangDao.selectDetail(id));
        }
        return new R(400,"fail",null);
    }

    @Override
    public R updateZnum(Integer mid, Integer znum,Integer zactive) {

        UpdateWrapper<Zancang> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("mid",mid);
        Zancang zancang = new Zancang();
        zancang.setZnum(znum);
        zancang.setZactive(zactive);
        if (zancangDao.update(zancang, updateWrapper)>0){
            return new R(200,"ok",zancangDao.selectDetail(mid));
        }
        return new R(400,"fail",null);
    }

    @Override
    public R updateCnum(Integer mid, Integer cnum,Integer cactive) {
        UpdateWrapper<Zancang> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("mid",mid);
        Zancang zancang = new Zancang();
        zancang.setCnum(cnum);
        zancang.setCactive(cactive);
        if (zancangDao.update(zancang, updateWrapper)>0){
            return new R(200,"ok",zancangDao.selectDetail(mid));
        }
        return new R(400,"fail",null);
    }
}
